﻿<%@ WebHandler Language="C#" Class="Assesment.Web.AjaxHandler.Transaction.AssesmentPositionIDPHandler" %>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;

using Assesment.Library.DataAccess.Administration;
using Assesment.Library.DomainObject.Administration;
using Assesment.Library.DataAccess.Administration.Catalog;
using Assesment.Library.DataAccess.Transaction;
using Assesment.Library.DomainObject.Transaction;
using Training.Library.DataAccess.Administration.Catalog;
using Training.Library.DomainObject.Administration.Catalog;
using SIPO.Library.DataAccess.Administration.Catalog;
using SIPO.Library.DomainObject.Administration.Catalog;

using Assesment.Library.Enum;
using Assesment.Web.Support;
using Newtonsoft.Json.Linq;
namespace Assesment.Web.AjaxHandler.Transaction
{

    public class AssesmentPositionIDPHandler : Assesment.Web.BaseHandler
    {
        private  AssesmentPositionIDPRepo AssesmentPositionIDPDal = new AssesmentPositionIDPRepo(ConfigurationManager.ConnectionStrings["AssesmentConn"].ConnectionString);
        private AssesmentPositionRepo AssesmentPositionDal = new AssesmentPositionRepo(ConfigurationManager.ConnectionStrings["AssesmentConn"].ConnectionString);
        private KaryawanRepo KaryawanDal = new KaryawanRepo(ConfigurationManager.ConnectionStrings["TrainingConn"].ConnectionString);
        private PositionRepo PositionDal = new PositionRepo(ConfigurationManager.ConnectionStrings["JobDescConn"].ConnectionString);
        private SIPO.Library.DataAccess.Administration.Catalog.CompetencyRepo CompetencyDal = new SIPO.Library.DataAccess.Administration.Catalog.CompetencyRepo(ConfigurationManager.ConnectionStrings["JobDescConn"].ConnectionString);
        private recLogRepo logDal = new recLogRepo(ConfigurationManager.ConnectionStrings["AssesmentConn"].ConnectionString);
        private string MethodName = string.Empty;

        public override void ProcessRequest(HttpContext context)
        {
            base.ProcessRequest(context);
            MethodName = context.Request.Params["method"];
            context.Response.Clear();
            context.Response.Buffer = true;

            System.IO.StreamReader sr = new System.IO.StreamReader(context.Request.InputStream);
            string jsonString = string.Empty;
            jsonString = context.Server.UrlDecode(sr.ReadToEnd());
            JObject jObj = string.IsNullOrEmpty(jsonString) ? null : JObject.Parse(jsonString);

            sr.Close();
            sr.Dispose();

            switch (MethodName.ToLower())
            {
                case ("insert"):
                    context.Response.Write(Insert(context, jObj));
                    break;
                case ("update"):
                    context.Response.Write(Update(context, jObj));
                    break;
                case ("delete"):
                    context.Response.Write(Delete(context, jObj));
                    break;
                case ("getdata"):
                    context.Response.Write(GetData(context));
                    break;

                default:
                    // do nothing
                    break;
            }

            context.Response.Flush();
            context.Response.End();
        }

        public override bool IsReusable
        {
            get
            {
                return false;
            }
        }

        private string Insert(HttpContext context, JObject jo)
        {
            JSONHelper helper = new JSONHelper();

            try
            {
                
                AssesmentPositionIDP obj = new AssesmentPositionIDP();
                obj.AssesmentPositionID = (int)jo["AssesmentPositionID"];
                obj.CreatedDate = DateTime.Now;
                obj.CreatedBy = base.UserLoggedIn;

                List<SIPO.Library.DomainObject.Administration.Catalog.Competency> listCompetency = CompetencyDal.GetList();
                var queryCustomerFocus = listCompetency.Where(x => x.CompetncyDesc.ToUpper().Contains("CUSTOMER FOCUS"));

                int IdCompetency = 0;
                foreach (SIPO.Library.DomainObject.Administration.Catalog.Competency data in queryCustomerFocus.ToList())
                {
                    IdCompetency = data.ComptID;
                }

                List<AssesmentPositionIDPDetail> listDetail = new List<AssesmentPositionIDPDetail>();
                AssesmentPositionIDPDetail objDetail = new AssesmentPositionIDPDetail();

                #region Group Customer Focus

                string AssesmentPositionDtlID = (string)jo["AssesmentPositionDtlIDCustomerFocus"];
                string[] arrAssesmentPositionDtlID = AssesmentPositionDtlID.Split('|');

                string MethodID = (string)jo["MethodIDCustomerFocus"];
                string[] arrMethodID = MethodID.Split('|');

                string SupportingPeople = (string)jo["SupportingPeopleCustomerFocus"];
                string[] arrSupportingPeople = SupportingPeople.Split('|');

                string StartDate = (string)jo["StartDateCustomerFocus"];
                string[] arrStartDate = StartDate.Split('|');

                string EndDate = (string)jo["EndDateCustomerFocus"];
                string[] arrEndDate = EndDate.Split('|');

                for (int i = 0; i < arrAssesmentPositionDtlID.Length - 1; i++)
                {
                    objDetail = new AssesmentPositionIDPDetail();
                    objDetail.CompetencyID = IdCompetency;
                    objDetail.AssesmentPositionDtlID = Convert.ToInt32(arrAssesmentPositionDtlID[i]);
                    objDetail.MethodID = Convert.ToInt32(arrMethodID[i]);
                    objDetail.DevelopmentActivity = (string)jo["DevelopmentActivityCustomerFocus"];
                    
                    
                    //objDetail.SupportingPeople = (string)jo["SupportingPeopleCustomerFocus"];
                    //objDetail.StartDate = (string)jo["StartDateCustomerFocus"];// Helper.FormatDate(jo["StartDateCostumerFocus"].ToString(), Helper.Culture.Indonesian);
                    //objDetail.EndDate = (string)jo["EndDateCustomerFocus"]; //Helper.FormatDate(jo["EndDateCostumerFocus"].ToString(), Helper.Culture.Indonesian);

                    objDetail.SupportingPeople = arrSupportingPeople[i].ToString();
                    objDetail.StartDate = arrStartDate[i].ToString();
                    objDetail.EndDate = arrEndDate[i].ToString();
                    
                    
                    
                    objDetail.CreatedBy = base.UserLoggedIn;
                    objDetail.CreatedDate = DateTime.Now;

                    listDetail.Add(objDetail);
                }

                #endregion


                #region Group Integrity

                queryCustomerFocus = listCompetency.Where(x => x.CompetncyDesc.ToUpper().Contains("INTEGRITY"));
                foreach (SIPO.Library.DomainObject.Administration.Catalog.Competency data in queryCustomerFocus.ToList())
                {
                    IdCompetency = data.ComptID;
                }

                 AssesmentPositionDtlID = (string)jo["AssesmentPositionDtlIDIntegrity"];
                 arrAssesmentPositionDtlID = AssesmentPositionDtlID.Split('|');

                 MethodID = (string)jo["MethodIDIntegrity"];
                 arrMethodID = MethodID.Split('|');

                 SupportingPeople = (string)jo["SupportingPeopleIntegrity"];
                 arrSupportingPeople = SupportingPeople.Split('|');

                 StartDate = (string)jo["StartDateIntegrity"];
                 arrStartDate = StartDate.Split('|');

                 EndDate = (string)jo["EndDateIntegrity"];
                 arrEndDate = EndDate.Split('|');

                for (int i = 0; i < arrAssesmentPositionDtlID.Length - 1; i++)
                {
                    objDetail = new AssesmentPositionIDPDetail();
                    objDetail.CompetencyID = IdCompetency;
                    objDetail.AssesmentPositionDtlID = Convert.ToInt32(arrAssesmentPositionDtlID[i]);
                    objDetail.MethodID = Convert.ToInt32(arrMethodID[i]);
                    objDetail.DevelopmentActivity = (string)jo["DevelopmentActivityIntegrity"];
                    
                    //objDetail.SupportingPeople = (string)jo["SupportingPeopleIntegrity"];
                    //objDetail.StartDate = (string)jo["StartDateIntegrity"];// Helper.FormatDate(jo["StartDateCostumerFocus"].ToString(), Helper.Culture.Indonesian);
                    //objDetail.EndDate = (string)jo["EndDateIntegrity"]; //Helper.FormatDate(jo["EndDateCostumerFocus"].ToString(), Helper.Culture.Indonesian);

                    objDetail.SupportingPeople = arrSupportingPeople[i].ToString();
                    objDetail.StartDate = arrStartDate[i].ToString();
                    objDetail.EndDate = arrEndDate[i].ToString();
                    
                    objDetail.CreatedBy = base.UserLoggedIn;
                    objDetail.CreatedDate = DateTime.Now;

                    listDetail.Add(objDetail);
                }

                #endregion


                #region Group Team Work

                queryCustomerFocus = listCompetency.Where(x => x.CompetncyDesc.ToUpper().Contains("TEAM WORK"));
                foreach (SIPO.Library.DomainObject.Administration.Catalog.Competency data in queryCustomerFocus.ToList())
                {
                    IdCompetency = data.ComptID;
                }

                AssesmentPositionDtlID = (string)jo["AssesmentPositionDtlIDTeamWork"];
                arrAssesmentPositionDtlID = AssesmentPositionDtlID.Split('|');

                MethodID = (string)jo["MethodIDTeamWork"];
                arrMethodID = MethodID.Split('|');

                SupportingPeople = (string)jo["SupportingPeopleTeamWork"];
                arrSupportingPeople = SupportingPeople.Split('|');

                StartDate = (string)jo["StartDateTeamWork"];
                arrStartDate = StartDate.Split('|');

                EndDate = (string)jo["EndDateTeamWork"];
                arrEndDate = EndDate.Split('|');

                for (int i = 0; i < arrAssesmentPositionDtlID.Length - 1; i++)
                {
                    objDetail = new AssesmentPositionIDPDetail();
                    objDetail.CompetencyID = IdCompetency;
                    objDetail.AssesmentPositionDtlID = Convert.ToInt32(arrAssesmentPositionDtlID[i]);
                    objDetail.MethodID = Convert.ToInt32(arrMethodID[i]);
                    objDetail.DevelopmentActivity = (string)jo["DevelopmentActivityTeamWork"];
                    
                    //objDetail.SupportingPeople = (string)jo["SupportingPeopleTeamWork"];
                    //objDetail.StartDate = (string)jo["StartDateTeamWork"];
                    //objDetail.EndDate = (string)jo["EndDateTeamWork"]; 

                    objDetail.SupportingPeople = arrSupportingPeople[i].ToString();
                    objDetail.StartDate = arrStartDate[i].ToString();
                    objDetail.EndDate = arrEndDate[i].ToString();
                    
                    objDetail.CreatedBy = base.UserLoggedIn;
                    objDetail.CreatedDate = DateTime.Now;

                    listDetail.Add(objDetail);
                }

                #endregion

                #region Group Continous Learning

                queryCustomerFocus = listCompetency.Where(x => x.CompetncyDesc.ToUpper().Contains("CONTINOUS LEARNING"));
                foreach (SIPO.Library.DomainObject.Administration.Catalog.Competency data in queryCustomerFocus.ToList())
                {
                    IdCompetency = data.ComptID;
                }

                AssesmentPositionDtlID = (string)jo["AssesmentPositionDtlIDContinous"];
                arrAssesmentPositionDtlID = AssesmentPositionDtlID.Split('|');

                MethodID = (string)jo["MethodIDContinous"];
                arrMethodID = MethodID.Split('|');

                SupportingPeople = (string)jo["SupportingPeopleContinous"];
                arrSupportingPeople = SupportingPeople.Split('|');

                StartDate = (string)jo["StartDateContinous"];
                arrStartDate = StartDate.Split('|');

                EndDate = (string)jo["EndDateContinous"];
                arrEndDate = EndDate.Split('|');

                for (int i = 0; i < arrAssesmentPositionDtlID.Length - 1; i++)
                {
                    objDetail = new AssesmentPositionIDPDetail();
                    objDetail.CompetencyID = IdCompetency;
                    objDetail.AssesmentPositionDtlID = Convert.ToInt32(arrAssesmentPositionDtlID[i]);
                    objDetail.MethodID = Convert.ToInt32(arrMethodID[i]);
                    objDetail.DevelopmentActivity = (string)jo["DevelopmentActivityContinous"];

                    //objDetail.SupportingPeople = (string)jo["SupportingPeopleTeamWork"];
                    //objDetail.StartDate = (string)jo["StartDateTeamWork"];
                    //objDetail.EndDate = (string)jo["EndDateTeamWork"]; 

                    objDetail.SupportingPeople = arrSupportingPeople[i].ToString();
                    objDetail.StartDate = arrStartDate[i].ToString();
                    objDetail.EndDate = arrEndDate[i].ToString();

                    objDetail.CreatedBy = base.UserLoggedIn;
                    objDetail.CreatedDate = DateTime.Now;

                    listDetail.Add(objDetail);
                }

                #endregion

                #region Group Work Excellence

                queryCustomerFocus = listCompetency.Where(x => x.CompetncyDesc.ToUpper().Contains("WORK EXCELLENCE"));
                foreach (SIPO.Library.DomainObject.Administration.Catalog.Competency data in queryCustomerFocus.ToList())
                {
                    IdCompetency = data.ComptID;
                }

                AssesmentPositionDtlID = (string)jo["AssesmentPositionDtlIDWorkExcellence"];
                arrAssesmentPositionDtlID = AssesmentPositionDtlID.Split('|');

                MethodID = (string)jo["MethodIDWorkExcellence"];
                arrMethodID = MethodID.Split('|');

                SupportingPeople = (string)jo["SupportingPeopleWorkExcellence"];
                arrSupportingPeople = SupportingPeople.Split('|');

                StartDate = (string)jo["StartDateWorkExcellence"];
                arrStartDate = StartDate.Split('|');

                EndDate = (string)jo["EndDateWorkExcellence"];
                arrEndDate = EndDate.Split('|');

                for (int i = 0; i < arrAssesmentPositionDtlID.Length - 1; i++)
                {
                    objDetail = new AssesmentPositionIDPDetail();
                    objDetail.CompetencyID = IdCompetency;
                    objDetail.AssesmentPositionDtlID = Convert.ToInt32(arrAssesmentPositionDtlID[i]);
                    objDetail.MethodID = Convert.ToInt32(arrMethodID[i]);
                    objDetail.DevelopmentActivity = (string)jo["DevelopmentActivityWorkExcellence"];

                    //objDetail.SupportingPeople = (string)jo["SupportingPeopleTeamWork"];
                    //objDetail.StartDate = (string)jo["StartDateTeamWork"];
                    //objDetail.EndDate = (string)jo["EndDateTeamWork"]; 

                    objDetail.SupportingPeople = arrSupportingPeople[i].ToString();
                    objDetail.StartDate = arrStartDate[i].ToString();
                    objDetail.EndDate = arrEndDate[i].ToString();

                    objDetail.CreatedBy = base.UserLoggedIn;
                    objDetail.CreatedDate = DateTime.Now;

                    listDetail.Add(objDetail);
                }

                #endregion


                

                #region Group B. FINANCIAL ACCUMENT

                queryCustomerFocus = listCompetency.Where(x => x.CompetncyDesc.ToUpper().Contains("BUSINESS FINANCIAL ACUMEN"));
                foreach (SIPO.Library.DomainObject.Administration.Catalog.Competency data in queryCustomerFocus.ToList())
                {
                    IdCompetency = data.ComptID;
                }

                AssesmentPositionDtlID = (string)jo["AssesmentPositionDtlIDFinancial"];
                arrAssesmentPositionDtlID = AssesmentPositionDtlID.Split('|');

                MethodID = (string)jo["MethodIDFinancial"];
                arrMethodID = MethodID.Split('|');

                SupportingPeople = (string)jo["SupportingPeopleFinancial"];
                arrSupportingPeople = SupportingPeople.Split('|');

                StartDate = (string)jo["StartDateFinancial"];
                arrStartDate = StartDate.Split('|');

                EndDate = (string)jo["EndDateFinancial"];
                arrEndDate = EndDate.Split('|');

                for (int i = 0; i < arrAssesmentPositionDtlID.Length - 1; i++)
                {
                    objDetail = new AssesmentPositionIDPDetail();
                    objDetail.CompetencyID = IdCompetency;
                    objDetail.AssesmentPositionDtlID = Convert.ToInt32(arrAssesmentPositionDtlID[i]);
                    objDetail.MethodID = Convert.ToInt32(arrMethodID[i]);
                    objDetail.DevelopmentActivity = (string)jo["DevelopmentActivityFinancial"];



                    objDetail.SupportingPeople = arrSupportingPeople[i].ToString();
                    objDetail.StartDate = arrStartDate[i].ToString();
                    objDetail.EndDate = arrEndDate[i].ToString();

                    objDetail.CreatedBy = base.UserLoggedIn;
                    objDetail.CreatedDate = DateTime.Now;

                    listDetail.Add(objDetail);
                }

                #endregion

                #region Group B. BUSSINES PARTNERSHIP

                queryCustomerFocus = listCompetency.Where(x => x.CompetncyDesc.ToUpper().Contains("BUSINESS PARTNERSHIP"));
                foreach (SIPO.Library.DomainObject.Administration.Catalog.Competency data in queryCustomerFocus.ToList())
                {
                    IdCompetency = data.ComptID;
                }

                AssesmentPositionDtlID = (string)jo["AssesmentPositionDtlIDBussines"];
                arrAssesmentPositionDtlID = AssesmentPositionDtlID.Split('|');

                MethodID = (string)jo["MethodIDBussines"];
                arrMethodID = MethodID.Split('|');

                SupportingPeople = (string)jo["SupportingPeopleBussines"];
                arrSupportingPeople = SupportingPeople.Split('|');

                StartDate = (string)jo["StartDateBussines"];
                arrStartDate = StartDate.Split('|');

                EndDate = (string)jo["EndDateBussines"];
                arrEndDate = EndDate.Split('|');

                for (int i = 0; i < arrAssesmentPositionDtlID.Length - 1; i++)
                {
                    objDetail = new AssesmentPositionIDPDetail();
                    objDetail.CompetencyID = IdCompetency;
                    objDetail.AssesmentPositionDtlID = Convert.ToInt32(arrAssesmentPositionDtlID[i]);
                    objDetail.MethodID = Convert.ToInt32(arrMethodID[i]);
                    objDetail.DevelopmentActivity = (string)jo["DevelopmentActivityBussines"];



                    objDetail.SupportingPeople = arrSupportingPeople[i].ToString();
                    objDetail.StartDate = arrStartDate[i].ToString();
                    objDetail.EndDate = arrEndDate[i].ToString();

                    objDetail.CreatedBy = base.UserLoggedIn;
                    objDetail.CreatedDate = DateTime.Now;

                    listDetail.Add(objDetail);
                }

                #endregion

                #region Group LEADERSHIP

                queryCustomerFocus = listCompetency.Where(x => x.CompetncyDesc.ToUpper().Contains("LEADERSHIP"));
                foreach (SIPO.Library.DomainObject.Administration.Catalog.Competency data in queryCustomerFocus.ToList())
                {
                    IdCompetency = data.ComptID;
                }

                AssesmentPositionDtlID = (string)jo["AssesmentPositionDtlIDLeadership"];
                arrAssesmentPositionDtlID = AssesmentPositionDtlID.Split('|');

                MethodID = (string)jo["MethodIDLeadership"];
                arrMethodID = MethodID.Split('|');

                SupportingPeople = (string)jo["SupportingPeopleLeadership"];
                arrSupportingPeople = SupportingPeople.Split('|');

                StartDate = (string)jo["StartDateLeadership"];
                arrStartDate = StartDate.Split('|');

                EndDate = (string)jo["EndDateLeadership"];
                arrEndDate = EndDate.Split('|');

                for (int i = 0; i < arrAssesmentPositionDtlID.Length - 1; i++)
                {
                    objDetail = new AssesmentPositionIDPDetail();
                    objDetail.CompetencyID = IdCompetency;
                    objDetail.AssesmentPositionDtlID = Convert.ToInt32(arrAssesmentPositionDtlID[i]);
                    objDetail.MethodID = Convert.ToInt32(arrMethodID[i]);
                    objDetail.DevelopmentActivity = (string)jo["DevelopmentActivityLeadership"];



                    objDetail.SupportingPeople = arrSupportingPeople[i].ToString();
                    objDetail.StartDate = arrStartDate[i].ToString();
                    objDetail.EndDate = arrEndDate[i].ToString();

                    objDetail.CreatedBy = base.UserLoggedIn;
                    objDetail.CreatedDate = DateTime.Now;

                    listDetail.Add(objDetail);
                }

                #endregion

                #region Group RESOURCE

                queryCustomerFocus = listCompetency.Where(x => x.CompetncyDesc.ToUpper().Contains("RESOURCE"));
                foreach (SIPO.Library.DomainObject.Administration.Catalog.Competency data in queryCustomerFocus.ToList())
                {
                    IdCompetency = data.ComptID;
                }

                AssesmentPositionDtlID = (string)jo["AssesmentPositionDtlIDResource"];
                arrAssesmentPositionDtlID = AssesmentPositionDtlID.Split('|');

                MethodID = (string)jo["MethodIDResource"];
                arrMethodID = MethodID.Split('|');

                SupportingPeople = (string)jo["SupportingPeopleResource"];
                arrSupportingPeople = SupportingPeople.Split('|');

                StartDate = (string)jo["StartDateResource"];
                arrStartDate = StartDate.Split('|');

                EndDate = (string)jo["EndDateResource"];
                arrEndDate = EndDate.Split('|');

                for (int i = 0; i < arrAssesmentPositionDtlID.Length - 1; i++)
                {
                    objDetail = new AssesmentPositionIDPDetail();
                    objDetail.CompetencyID = IdCompetency;
                    objDetail.AssesmentPositionDtlID = Convert.ToInt32(arrAssesmentPositionDtlID[i]);
                    objDetail.MethodID = Convert.ToInt32(arrMethodID[i]);
                    objDetail.DevelopmentActivity = (string)jo["DevelopmentActivityResource"];



                    objDetail.SupportingPeople = arrSupportingPeople[i].ToString();
                    objDetail.StartDate = arrStartDate[i].ToString();
                    objDetail.EndDate = arrEndDate[i].ToString();

                    objDetail.CreatedBy = base.UserLoggedIn;
                    objDetail.CreatedDate = DateTime.Now;

                    listDetail.Add(objDetail);
                }

                #endregion
                

                AssesmentPositionIDPDal.Save(obj,listDetail);

                helper.Message = "Data berhasil di simpan !";
                helper.IsSuccess = true;

            }
            catch (Exception ex)
            {

                helper.Message = ex.Message;
                helper.IsSuccess = false;
            }
            finally
            {
                recLog log = new recLog();
                log.LogEvent = "Insert";
                log.LogMessage = helper.Message;
                log.LogSource = "AssesmentPositionIDPhandler.ashx";
                log.CreatedBy = base.UserLoggedIn;
                log.CreatedDate = DateTime.Now;
                logDal.Save(log);

            }

            return Newtonsoft.Json.JsonConvert.SerializeObject(helper);

        }

        private string Update(HttpContext context, JObject jo)
        {
            JSONHelper helper = new JSONHelper();

            try
            {


                AssesmentPositionIDP obj = new AssesmentPositionIDP();
                //obj.AssesmentPositionID = (int)jo["AssesmentPositionID"];
                //obj.CreatedDate = DateTime.Now;
                //obj.CreatedBy = base.UserLoggedIn;

                obj.AssesmentIdpID = (int)jo["AssesmentIdpID"];
                obj.UpdatedBy = base.UserLoggedIn;
                obj.CreatedDate = DateTime.Now;

                List<SIPO.Library.DomainObject.Administration.Catalog.Competency> listCompetency = CompetencyDal.GetList();
                var queryCustomerFocus = listCompetency.Where(x => x.CompetncyDesc.ToUpper().Contains("CUSTOMER FOCUS"));

                int IdCompetency = 0;
                foreach (SIPO.Library.DomainObject.Administration.Catalog.Competency data in queryCustomerFocus.ToList())
                {
                    IdCompetency = data.ComptID;
                }

                List<AssesmentPositionIDPDetail> listDetail = new List<AssesmentPositionIDPDetail>();
                AssesmentPositionIDPDetail objDetail = new AssesmentPositionIDPDetail();

                #region Group Customer Focus

                string AssesmentPositionDtlID = (string)jo["AssesmentPositionDtlIDCustomerFocus"];
                string[] arrAssesmentPositionDtlID = AssesmentPositionDtlID.Split('|');

                string MethodID = (string)jo["MethodIDCustomerFocus"];
                string[] arrMethodID = MethodID.Split('|');

                string SupportingPeople = (string)jo["SupportingPeopleCustomerFocus"];
                string[] arrSupportingPeople = SupportingPeople.Split('|');

                string StartDate = (string)jo["StartDateCustomerFocus"];
                string[] arrStartDate = StartDate.Split('|');

                string EndDate = (string)jo["EndDateCustomerFocus"];
                string[] arrEndDate = EndDate.Split('|');

                for (int i = 0; i < arrAssesmentPositionDtlID.Length - 1; i++)
                {
                    objDetail = new AssesmentPositionIDPDetail();
                    objDetail.CompetencyID = IdCompetency;
                    objDetail.AssesmentPositionDtlID = Convert.ToInt32(arrAssesmentPositionDtlID[i]);
                    objDetail.MethodID = Convert.ToInt32(arrMethodID[i]);
                    objDetail.DevelopmentActivity = (string)jo["DevelopmentActivityCustomerFocus"];


                    //objDetail.SupportingPeople = (string)jo["SupportingPeopleCustomerFocus"];
                    //objDetail.StartDate = (string)jo["StartDateCustomerFocus"];// Helper.FormatDate(jo["StartDateCostumerFocus"].ToString(), Helper.Culture.Indonesian);
                    //objDetail.EndDate = (string)jo["EndDateCustomerFocus"]; //Helper.FormatDate(jo["EndDateCostumerFocus"].ToString(), Helper.Culture.Indonesian);

                    objDetail.SupportingPeople = arrSupportingPeople[i].ToString();
                    objDetail.StartDate = arrStartDate[i].ToString();
                    objDetail.EndDate = arrEndDate[i].ToString();



                    objDetail.CreatedBy = base.UserLoggedIn;
                    objDetail.CreatedDate = DateTime.Now;

                    listDetail.Add(objDetail);
                }

                #endregion


                #region Group Integrity

                queryCustomerFocus = listCompetency.Where(x => x.CompetncyDesc.ToUpper().Contains("INTEGRITY"));
                foreach (SIPO.Library.DomainObject.Administration.Catalog.Competency data in queryCustomerFocus.ToList())
                {
                    IdCompetency = data.ComptID;
                }

                AssesmentPositionDtlID = (string)jo["AssesmentPositionDtlIDIntegrity"];
                arrAssesmentPositionDtlID = AssesmentPositionDtlID.Split('|');

                MethodID = (string)jo["MethodIDIntegrity"];
                arrMethodID = MethodID.Split('|');

                SupportingPeople = (string)jo["SupportingPeopleIntegrity"];
                arrSupportingPeople = SupportingPeople.Split('|');

                StartDate = (string)jo["StartDateIntegrity"];
                arrStartDate = StartDate.Split('|');

                EndDate = (string)jo["EndDateIntegrity"];
                arrEndDate = EndDate.Split('|');

                for (int i = 0; i < arrAssesmentPositionDtlID.Length - 1; i++)
                {
                    objDetail = new AssesmentPositionIDPDetail();
                    objDetail.CompetencyID = IdCompetency;
                    objDetail.AssesmentPositionDtlID = Convert.ToInt32(arrAssesmentPositionDtlID[i]);
                    objDetail.MethodID = Convert.ToInt32(arrMethodID[i]);
                    objDetail.DevelopmentActivity = (string)jo["DevelopmentActivityIntegrity"];

                    //objDetail.SupportingPeople = (string)jo["SupportingPeopleIntegrity"];
                    //objDetail.StartDate = (string)jo["StartDateIntegrity"];// Helper.FormatDate(jo["StartDateCostumerFocus"].ToString(), Helper.Culture.Indonesian);
                    //objDetail.EndDate = (string)jo["EndDateIntegrity"]; //Helper.FormatDate(jo["EndDateCostumerFocus"].ToString(), Helper.Culture.Indonesian);

                    objDetail.SupportingPeople = arrSupportingPeople[i].ToString();
                    objDetail.StartDate = arrStartDate[i].ToString();
                    objDetail.EndDate = arrEndDate[i].ToString();

                    objDetail.CreatedBy = base.UserLoggedIn;
                    objDetail.CreatedDate = DateTime.Now;

                    listDetail.Add(objDetail);
                }

                #endregion


                #region Group Team Work

                queryCustomerFocus = listCompetency.Where(x => x.CompetncyDesc.ToUpper().Contains("TEAM WORK"));
                foreach (SIPO.Library.DomainObject.Administration.Catalog.Competency data in queryCustomerFocus.ToList())
                {
                    IdCompetency = data.ComptID;
                }

                AssesmentPositionDtlID = (string)jo["AssesmentPositionDtlIDTeamWork"];
                arrAssesmentPositionDtlID = AssesmentPositionDtlID.Split('|');

                MethodID = (string)jo["MethodIDTeamWork"];
                arrMethodID = MethodID.Split('|');

                SupportingPeople = (string)jo["SupportingPeopleTeamWork"];
                arrSupportingPeople = SupportingPeople.Split('|');

                StartDate = (string)jo["StartDateTeamWork"];
                arrStartDate = StartDate.Split('|');

                EndDate = (string)jo["EndDateTeamWork"];
                arrEndDate = EndDate.Split('|');

                for (int i = 0; i < arrAssesmentPositionDtlID.Length - 1; i++)
                {
                    objDetail = new AssesmentPositionIDPDetail();
                    objDetail.CompetencyID = IdCompetency;
                    objDetail.AssesmentPositionDtlID = Convert.ToInt32(arrAssesmentPositionDtlID[i]);
                    objDetail.MethodID = Convert.ToInt32(arrMethodID[i]);
                    objDetail.DevelopmentActivity = (string)jo["DevelopmentActivityTeamWork"];

                    //objDetail.SupportingPeople = (string)jo["SupportingPeopleTeamWork"];
                    //objDetail.StartDate = (string)jo["StartDateTeamWork"];
                    //objDetail.EndDate = (string)jo["EndDateTeamWork"]; 

                    objDetail.SupportingPeople = arrSupportingPeople[i].ToString();
                    objDetail.StartDate = arrStartDate[i].ToString();
                    objDetail.EndDate = arrEndDate[i].ToString();

                    objDetail.CreatedBy = base.UserLoggedIn;
                    objDetail.CreatedDate = DateTime.Now;

                    listDetail.Add(objDetail);
                }

                #endregion

                #region Group Continous Learning

                queryCustomerFocus = listCompetency.Where(x => x.CompetncyDesc.ToUpper().Contains("CONTINOUS LEARNING"));
                foreach (SIPO.Library.DomainObject.Administration.Catalog.Competency data in queryCustomerFocus.ToList())
                {
                    IdCompetency = data.ComptID;
                }

                AssesmentPositionDtlID = (string)jo["AssesmentPositionDtlIDContinous"];
                arrAssesmentPositionDtlID = AssesmentPositionDtlID.Split('|');

                MethodID = (string)jo["MethodIDContinous"];
                arrMethodID = MethodID.Split('|');

                SupportingPeople = (string)jo["SupportingPeopleContinous"];
                arrSupportingPeople = SupportingPeople.Split('|');

                StartDate = (string)jo["StartDateContinous"];
                arrStartDate = StartDate.Split('|');

                EndDate = (string)jo["EndDateContinous"];
                arrEndDate = EndDate.Split('|');

                for (int i = 0; i < arrAssesmentPositionDtlID.Length - 1; i++)
                {
                    objDetail = new AssesmentPositionIDPDetail();
                    objDetail.CompetencyID = IdCompetency;
                    objDetail.AssesmentPositionDtlID = Convert.ToInt32(arrAssesmentPositionDtlID[i]);
                    objDetail.MethodID = Convert.ToInt32(arrMethodID[i]);
                    objDetail.DevelopmentActivity = (string)jo["DevelopmentActivityContinous"];

                    //objDetail.SupportingPeople = (string)jo["SupportingPeopleTeamWork"];
                    //objDetail.StartDate = (string)jo["StartDateTeamWork"];
                    //objDetail.EndDate = (string)jo["EndDateTeamWork"]; 

                    objDetail.SupportingPeople = arrSupportingPeople[i].ToString();
                    objDetail.StartDate = arrStartDate[i].ToString();
                    objDetail.EndDate = arrEndDate[i].ToString();

                    objDetail.CreatedBy = base.UserLoggedIn;
                    objDetail.CreatedDate = DateTime.Now;

                    listDetail.Add(objDetail);
                }

                #endregion

                #region Group Work Excellence

                queryCustomerFocus = listCompetency.Where(x => x.CompetncyDesc.ToUpper().Contains("WORK EXCELLENCE"));
                foreach (SIPO.Library.DomainObject.Administration.Catalog.Competency data in queryCustomerFocus.ToList())
                {
                    IdCompetency = data.ComptID;
                }

                AssesmentPositionDtlID = (string)jo["AssesmentPositionDtlIDWorkExcellence"];
                arrAssesmentPositionDtlID = AssesmentPositionDtlID.Split('|');

                MethodID = (string)jo["MethodIDWorkExcellence"];
                arrMethodID = MethodID.Split('|');

                SupportingPeople = (string)jo["SupportingPeopleWorkExcellence"];
                arrSupportingPeople = SupportingPeople.Split('|');

                StartDate = (string)jo["StartDateWorkExcellence"];
                arrStartDate = StartDate.Split('|');

                EndDate = (string)jo["EndDateWorkExcellence"];
                arrEndDate = EndDate.Split('|');

                for (int i = 0; i < arrAssesmentPositionDtlID.Length - 1; i++)
                {
                    objDetail = new AssesmentPositionIDPDetail();
                    objDetail.CompetencyID = IdCompetency;
                    objDetail.AssesmentPositionDtlID = Convert.ToInt32(arrAssesmentPositionDtlID[i]);
                    objDetail.MethodID = Convert.ToInt32(arrMethodID[i]);
                    objDetail.DevelopmentActivity = (string)jo["DevelopmentActivityWorkExcellence"];

                    //objDetail.SupportingPeople = (string)jo["SupportingPeopleTeamWork"];
                    //objDetail.StartDate = (string)jo["StartDateTeamWork"];
                    //objDetail.EndDate = (string)jo["EndDateTeamWork"]; 

                    objDetail.SupportingPeople = arrSupportingPeople[i].ToString();
                    objDetail.StartDate = arrStartDate[i].ToString();
                    objDetail.EndDate = arrEndDate[i].ToString();

                    objDetail.CreatedBy = base.UserLoggedIn;
                    objDetail.CreatedDate = DateTime.Now;

                    listDetail.Add(objDetail);
                }

                #endregion




                #region Group B. FINANCIAL ACCUMENT

                queryCustomerFocus = listCompetency.Where(x => x.CompetncyDesc.ToUpper().Contains("BUSINESS FINANCIAL ACUMEN"));
                foreach (SIPO.Library.DomainObject.Administration.Catalog.Competency data in queryCustomerFocus.ToList())
                {
                    IdCompetency = data.ComptID;
                }

                AssesmentPositionDtlID = (string)jo["AssesmentPositionDtlIDFinancial"];
                arrAssesmentPositionDtlID = AssesmentPositionDtlID.Split('|');

                MethodID = (string)jo["MethodIDFinancial"];
                arrMethodID = MethodID.Split('|');

                SupportingPeople = (string)jo["SupportingPeopleFinancial"];
                arrSupportingPeople = SupportingPeople.Split('|');

                StartDate = (string)jo["StartDateFinancial"];
                arrStartDate = StartDate.Split('|');

                EndDate = (string)jo["EndDateFinancial"];
                arrEndDate = EndDate.Split('|');

                for (int i = 0; i < arrAssesmentPositionDtlID.Length - 1; i++)
                {
                    objDetail = new AssesmentPositionIDPDetail();
                    objDetail.CompetencyID = IdCompetency;
                    objDetail.AssesmentPositionDtlID = Convert.ToInt32(arrAssesmentPositionDtlID[i]);
                    objDetail.MethodID = Convert.ToInt32(arrMethodID[i]);
                    objDetail.DevelopmentActivity = (string)jo["DevelopmentActivityFinancial"];



                    objDetail.SupportingPeople = arrSupportingPeople[i].ToString();
                    objDetail.StartDate = arrStartDate[i].ToString();
                    objDetail.EndDate = arrEndDate[i].ToString();

                    objDetail.CreatedBy = base.UserLoggedIn;
                    objDetail.CreatedDate = DateTime.Now;

                    listDetail.Add(objDetail);
                }

                #endregion

                #region Group B. BUSSINES PARTNERSHIP

                queryCustomerFocus = listCompetency.Where(x => x.CompetncyDesc.ToUpper().Contains("BUSINESS PARTNERSHIP"));
                foreach (SIPO.Library.DomainObject.Administration.Catalog.Competency data in queryCustomerFocus.ToList())
                {
                    IdCompetency = data.ComptID;
                }

                AssesmentPositionDtlID = (string)jo["AssesmentPositionDtlIDBussines"];
                arrAssesmentPositionDtlID = AssesmentPositionDtlID.Split('|');

                MethodID = (string)jo["MethodIDBussines"];
                arrMethodID = MethodID.Split('|');

                SupportingPeople = (string)jo["SupportingPeopleBussines"];
                arrSupportingPeople = SupportingPeople.Split('|');

                StartDate = (string)jo["StartDateBussines"];
                arrStartDate = StartDate.Split('|');

                EndDate = (string)jo["EndDateBussines"];
                arrEndDate = EndDate.Split('|');

                for (int i = 0; i < arrAssesmentPositionDtlID.Length - 1; i++)
                {
                    objDetail = new AssesmentPositionIDPDetail();
                    objDetail.CompetencyID = IdCompetency;
                    objDetail.AssesmentPositionDtlID = Convert.ToInt32(arrAssesmentPositionDtlID[i]);
                    objDetail.MethodID = Convert.ToInt32(arrMethodID[i]);
                    objDetail.DevelopmentActivity = (string)jo["DevelopmentActivityBussines"];



                    objDetail.SupportingPeople = arrSupportingPeople[i].ToString();
                    objDetail.StartDate = arrStartDate[i].ToString();
                    objDetail.EndDate = arrEndDate[i].ToString();

                    objDetail.CreatedBy = base.UserLoggedIn;
                    objDetail.CreatedDate = DateTime.Now;

                    listDetail.Add(objDetail);
                }

                #endregion

                #region Group LEADERSHIP

                queryCustomerFocus = listCompetency.Where(x => x.CompetncyDesc.ToUpper().Contains("LEADERSHIP"));
                foreach (SIPO.Library.DomainObject.Administration.Catalog.Competency data in queryCustomerFocus.ToList())
                {
                    IdCompetency = data.ComptID;
                }

                AssesmentPositionDtlID = (string)jo["AssesmentPositionDtlIDLeadership"];
                arrAssesmentPositionDtlID = AssesmentPositionDtlID.Split('|');

                MethodID = (string)jo["MethodIDLeadership"];
                arrMethodID = MethodID.Split('|');

                SupportingPeople = (string)jo["SupportingPeopleLeadership"];
                arrSupportingPeople = SupportingPeople.Split('|');

                StartDate = (string)jo["StartDateLeadership"];
                arrStartDate = StartDate.Split('|');

                EndDate = (string)jo["EndDateLeadership"];
                arrEndDate = EndDate.Split('|');

                for (int i = 0; i < arrAssesmentPositionDtlID.Length - 1; i++)
                {
                    objDetail = new AssesmentPositionIDPDetail();
                    objDetail.CompetencyID = IdCompetency;
                    objDetail.AssesmentPositionDtlID = Convert.ToInt32(arrAssesmentPositionDtlID[i]);
                    objDetail.MethodID = Convert.ToInt32(arrMethodID[i]);
                    objDetail.DevelopmentActivity = (string)jo["DevelopmentActivityLeadership"];



                    objDetail.SupportingPeople = arrSupportingPeople[i].ToString();
                    objDetail.StartDate = arrStartDate[i].ToString();
                    objDetail.EndDate = arrEndDate[i].ToString();

                    objDetail.CreatedBy = base.UserLoggedIn;
                    objDetail.CreatedDate = DateTime.Now;

                    listDetail.Add(objDetail);
                }

                #endregion

                #region Group RESOURCE

                queryCustomerFocus = listCompetency.Where(x => x.CompetncyDesc.ToUpper().Contains("RESOURCE"));
                foreach (SIPO.Library.DomainObject.Administration.Catalog.Competency data in queryCustomerFocus.ToList())
                {
                    IdCompetency = data.ComptID;
                }

                AssesmentPositionDtlID = (string)jo["AssesmentPositionDtlIDResource"];
                arrAssesmentPositionDtlID = AssesmentPositionDtlID.Split('|');

                MethodID = (string)jo["MethodIDResource"];
                arrMethodID = MethodID.Split('|');

                SupportingPeople = (string)jo["SupportingPeopleResource"];
                arrSupportingPeople = SupportingPeople.Split('|');

                StartDate = (string)jo["StartDateResource"];
                arrStartDate = StartDate.Split('|');

                EndDate = (string)jo["EndDateResource"];
                arrEndDate = EndDate.Split('|');

                for (int i = 0; i < arrAssesmentPositionDtlID.Length - 1; i++)
                {
                    objDetail = new AssesmentPositionIDPDetail();
                    objDetail.CompetencyID = IdCompetency;
                    objDetail.AssesmentPositionDtlID = Convert.ToInt32(arrAssesmentPositionDtlID[i]);
                    objDetail.MethodID = Convert.ToInt32(arrMethodID[i]);
                    objDetail.DevelopmentActivity = (string)jo["DevelopmentActivityResource"];



                    objDetail.SupportingPeople = arrSupportingPeople[i].ToString();
                    objDetail.StartDate = arrStartDate[i].ToString();
                    objDetail.EndDate = arrEndDate[i].ToString();

                    objDetail.CreatedBy = base.UserLoggedIn;
                    objDetail.CreatedDate = DateTime.Now;

                    listDetail.Add(objDetail);
                }

                #endregion

                AssesmentPositionIDPDal.Update(obj, listDetail);
                
                helper.Message = "Data berhasil di ubah !";
                helper.IsSuccess = true;
            }
            catch (Exception ex)
            {
                helper.IsSuccess = false;
                helper.Message = ex.Message;
            }
            finally
            {
                recLog log = new recLog();
                log.LogEvent = "Update";
                log.LogMessage = helper.Message;
                log.LogSource = "AssesmentPositionIDPhandler.ashx";
                log.CreatedBy = base.UserLoggedIn;
                log.CreatedDate = DateTime.Now;
                logDal.Save(log);
            }

            return Newtonsoft.Json.JsonConvert.SerializeObject(helper);

        }

        private string Delete(HttpContext context, JObject jo)
        {
            JSONHelper helper = new JSONHelper();

            try
            {
                var strId = (string)jo["ID"];

                string[] ids = strId.Split(',');
                foreach (string id in ids)
                {
                    int intID = Convert.ToInt32(id);
                    AssesmentPositionIDPDal.DeleteWithDetail(intID);
                }

                helper.IsSuccess = true;
                helper.Message = "Data berhasil di hapus !";
            }
            catch (Exception ex)
            {
                helper.IsSuccess = false;
                helper.Message = ex.Message;
            }
            finally
            {
                recLog log = new recLog();
                log.LogEvent = "Delete";
                log.LogMessage = helper.Message;
                log.LogSource = "AssesmentPositionIDPhandler.ashx";
                log.CreatedBy = base.UserLoggedIn;
                log.CreatedDate = DateTime.Now;
                logDal.Save(log);

            }

            return Newtonsoft.Json.JsonConvert.SerializeObject(helper);

        }

        private string GetData(HttpContext context)
        {
            string parameters = Helper.JqGridFilterToSQLParams(context);

            int page = 1;
            int.TryParse(context.Request.QueryString["page"] ?? "1", out page);

            int pageSize = 10;
            int.TryParse(context.Request.QueryString["rows"] ?? "10", out pageSize);

            string sidx = ((context.Request.QueryString["sidx"]) == null ? AssesmentPositionIDP.Fields.AssesmentIdpID : context.Request.QueryString["sidx"].ToString());

            string sord = ((context.Request.QueryString["sord"]) == null ? "ASC" : context.Request.QueryString["sord"].ToString());

            int totalCount = 0;
            int totalPages = 0;
            List<AssesmentPositionIDP> pagedList = null;

            try
            {
                totalCount = Convert.ToInt32(AssesmentPositionIDPDal.SelectScalar(SQL.Function.Aggregate.Count, AssesmentPositionIDP.Fields.AssesmentIdpID, parameters));

                decimal dc = decimal.Ceiling(Convert.ToDecimal(totalCount) / Convert.ToDecimal(pageSize));
                totalPages = Convert.ToInt32(dc);

                pagedList = AssesmentPositionIDPDal.GetList(pageSize, page, sidx, sord, parameters);
            }
            catch (Exception ex)
            {
                recLog log = new recLog();
                log.LogEvent = "GetData";
                log.LogMessage = ex.Message;
                log.LogSource = "AssesmentPositionIDPhandler.ashx";
                log.CreatedBy = base.UserLoggedIn;
                log.CreatedDate = DateTime.Now;
                logDal.Save(log);
                log.Dispose();
            }
            finally
            {

            }

            // send params into jqGrid's format
            var gridData = new
            {
                page = page,
                total = totalPages,
                records = totalCount,
                rows = pagedList,
            };

            return Newtonsoft.Json.JsonConvert.SerializeObject(gridData);

        }

    }

}